<template>
  <div class="message">
    <div class="i-layout-page-header">
      <span class="ivu-page-header-title">{{ $route.meta.title }}</span>
    </div>
    <div class="table-box" style="padding-bottom: 0">
      <Card :bordered="false" dis-hover class="">
		  <Form>
			<Row type="flex" :gutter="24">
			  <Col v-bind="grid">
				<FormItem label="项目名称:">
				  <div class="add">
					<span>{{projectData.name}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="所属合同:">
				  <div class="add">
					<span>{{projectData.contract_name}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="项目编号:">
				  <div class="add">
					<span>{{projectData.code}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="项目经理:">
				  <div class="add">
					<span>{{projectData.leader_name}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="开始时间:">
				  <div class="add">
					<span>{{projectData.start_time}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="结束时间:">
				  <div class="add">
					<span>{{projectData.end_time}}</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="截止工时:">
				  <div class="add">
					<span>{{projectData.worktime}}人天</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="项目状态:">
				  <div class="add">
					<span v-if="projectData.status == 0">未开始</span>
					<span v-if="projectData.status == 1">进行中</span>
					<span v-if="projectData.status == 2">已完成</span>
					<span v-if="projectData.status == 3">已暂停</span>
					<span v-if="projectData.status == 4">已取消</span>
				  </div>
				</FormItem>
			  </Col>
			  <Col v-bind="grid">
				<FormItem label="完成进度:">
				  <div class="add">
					<span>{{projectData.percent}}%</span>
				  </div>
				</FormItem>
			  </Col>
			  
			 </Row>
			 <Row type="flex" :gutter="24">
				 <Col :xs="24">
						<FormItem label="备注:">
						  <div class="add">
							<span>{{projectData.remark}}</span>
						  </div>
						</FormItem>
				 </Col>
			 </Row>
		  </Form>
      </Card>
    </div>
    
    <!-- 缩略图配置 -->
    <div class="table-box" style="padding-top: 10px">
      <Card :bordered="false" dis-hover class="ivu-mt">
        <Row type="flex" class="mb20">
		  <Col span="24">
			<span style="padding: 0px 0px 20px 0px;display: block">工时记录</span>
		  </Col>
          <Col span="24">
            <Button v-auth="['admin-contract-foud-add']" type="primary" @click="writeWorkTime()">填报工时</Button>
          </Col>
        </Row>
        <Table
          :columns="columns"
          :data="foudLists"
          ref="table"
          class="mt25"
          :loading="loading"
          highlight-row
          no-userFrom-text="暂无数据"
          no-filtered-userFrom-text="暂无筛选结果"
        >
          <template slot-scope="{ row, index }" slot="status">
            <!-- {{row}}{{index}} -->
            <i-switch
              v-model="row.status"
              :value="row.status"
              :true-value="1"
              :false-value="0"
              @on-change="changeSwitch(row, index)"
              size="large"
            >
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
            </i-switch>
          </template>
          <template slot-scope="{ row, index }" slot="action">
            <span v-if="(current_uid == row.created_uid || current_uid == 1) && (row.status ==0|| row.status == 2)"  class="btn" @click="editFoud(row)">编辑</span>
            <Divider v-if="(current_uid == row.created_uid || current_uid == 1) && (row.status ==0|| row.status == 2)"  type="vertical" />
            <span v-if="(current_uid == row.created_uid || current_uid == 1) && (row.status ==0|| row.status == 2)"  class="btn" @click="del(row, '删除该数据', index)">删除</span>
          </template>
		  <template slot-scope="{ row, index }" slot="status">
		    <span v-if="row.status == 0">待审核</span>
		    <span v-else-if="row.status == 1">已通过</span>
		    <span v-else="row.status == 2">未通过</span>
			<p v-if="row.status==2" style="color: red;font-size: 8px;">【{{row.reason}}】</p>
		 </template>
        </Table>
		  <div class="acea-row row-right page">
			<Page
			  :total="page.total"
			  :current="page.pageNum"
			  show-elevator
			  show-total
			  @on-change="pageChange"
			  :page-size="page.pageSize"
			  @on-page-size-change="limitChange"
			/>
		  </div>
      </Card>
	  
	  
    </div>
    <Modal v-model="configuModal" title="CNAME配置">
      <div>
        <div class="confignv"><span class="configtit">主机记录：</span>{{ configData.domain }}</div>
        <div class="confignv"><span class="configtit">记录类型：</span>CNAME</div>
        <div class="confignv">
          <span class="configtit">记录值：</span>{{ configData.cname }}
          <span class="copy copy-data" :data-clipboard-text="configData.cname">复制</span>
        </div>
      </div>
      <div slot="footer"></div>
    </Modal>
    <menus-from
      :formValidate="formValidate"
      :titleFrom="titleFrom"
      @getFoud="getWorks"
      @selectRule="selectRule"
      ref="menusFrom"
      @clearFrom="clearFrom"
    ></menus-from>
  </div>
</template>

<script>
import ClipboardJS from 'clipboard';
import uploadPictures from '@/components/uploadPictures';
import menusFrom from './components/menusFrom';

import {ListWorksApi} from '@/api/work';
import {ListTicketApi} from '@/api/ticket';
import {detailApi} from '@/api/project';
import {
  storageConfigApi,
  addConfigApi,
  addStorageApi,
  storageListApi,
  storageSynchApi,
  storageSwitchApi,
  storageStatusApi,
  editStorageApi,
  positionInfoApi,
  positionPostApi,
  saveType,
} from '@/api/setting';
export default {
  components: { uploadPictures,menusFrom },
  data() {
    return {
      saveType: 0,
      isChoice: '单选',
      gridBtn: {
        xl: 4,
        lg: 8,
        md: 8,
        sm: 8,
        xs: 8,
      },
      gridPic: {
        xl: 6,
        lg: 8,
        md: 12,
        sm: 12,
        xs: 12,
      },
	  
	  grid: {
	    xl: 8,
	    lg: 8,
	    md: 8,
	    sm: 24,
	    xs: 24,
	  },
      positionId: 1,
      positiontlt: '',
      formValidate: {
		contract_id:this.$route.params.id
      },
      boxs: [
        { content: '左上', id: 1 },
        { content: '上', id: 2 },
        { content: '右上', id: 3 },
        { content: '左中', id: 4 },
        { content: '中', id: 5 },
        { content: '右中', id: 6 },
        { content: '左下', id: 7 },
        { content: '下', id: 8 },
        { content: '右下', id: 9 },
      ],
      ruleValidate: {},
      configuModal: false,
      configData: '',
	  projectData: '',
      columns: [
        {
          title: '序号',
          key: 'id',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '部门',
          key: 'dept_name',
          align: 'center',
          minWidth: 100,
        },
        {
          title: '填报人员',
          key: 'user_name',
          align: 'center',
          minWidth: 100,
        },
        {
          title: '开始时间',
          key: 'start_time',
          align: 'center',
          width: 100,
        },
        {
          title: '结束时间',
          key: 'end_time',
          align: 'center',
          width: 100,
        },
        {
          title: '工时(人天)',
          key: 'time',
          align: 'center',
          minWidth: 150,
        },
        {
          title: '状态',
          slot: 'status',
          align: 'center',
          minWidth: 80,
        },
        {
          title: '备注',
          key: 'content',
          align: 'center',
          minWidth: 200,
        },
        {
          title: '操作',
          slot: 'action',
          width: 100,
          align: 'center',
        },
      ],
      total: 0,
      page: {
        total: 0, // 总条数
        pageNum: 1, // 当前页
        pageSize: 10, // 每页显示条数
      },
      foudLists: [],
      currentTab: '1',
      loading: false,
	  current_uid:0,
      addData: {
        input: '',
        select: '',
        jurisdiction: '1',
        type: '1',
      },
      confData: {
        AccessKeyId: '',
        AccessKeySecret: '',
      },
      localStorage: false,
	  titleFrom:''
    };
  },
  created() {
	  
  },
  mounted: function () {
    this.$nextTick(function () {
      const clipboard = new ClipboardJS('.copy-data');
      clipboard.on('success', () => {
        this.$Message.success('复制成功');
      });
    });
	this.getData();
	this.getWorks();
  },
  methods: {
	//填报工时
	writeWorkTime(){
	  this.formValidate = {
			p_id:this.$route.params.id,
	  };
	  this.titleFrom = '填报工时';
	  this.$refs.menusFrom.modals = true;
	},
	//编辑工时
	editFoud(row) {
		this.titleFrom = '编辑工时';
	    this.formValidate = {};
		this.formValidate = {
			id:row.id,
			p_id:this.$route.params.id,
			start_time: row.start_time,
			end_time:row.end_time,
			time:row.time,
			content:row.content
		};
	    this.$refs.menusFrom.valids = false;
	    this.$refs.menusFrom.getAddFrom(row.id);
	    this.$refs.menusFrom.modals = true;
	},
	//获取工时记录
	getWorks(){
		this.loading = true;
		ListWorksApi({'project_id':this.$route.params.id})
		  .then((res) => {
			  console.info(res)
			  let data = res.data;
			  this.foudLists = data.list;
			  this.page.total = data.count;
			  this.current_uid = data.current_uid;
			  this.loading = false;
		  })
		  .catch((err) => {
			  this.loading = false;
		    this.$Message.error(err.msg);
		  });
	},
	//获取项目信息
	getData(){
		detailApi(this.$route.params.id)
		  .then((res) => {
			  console.info(res)
			  this.projectData = res.data;
			  this.projectData.attach = JSON.parse(res.data.attach);
		  })
		  .catch((err) => {
		    this.$Message.error(err.msg);
		  });
	},
    // 删除
    del(row, tit, num) {
      let delfromData = {
        title: '删除数据',
        url: `/work/del/${row.id}`,
        method: 'GET',
        ids: '',
      };
      this.$modalSure(delfromData)
        .then((res) => {
          this.$Message.success(res.msg);
          this.getWorks();
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.page.pageNum = index;
      this.getlist();
    },
  },
};
</script>
<style scoped lang="less">
.ivu-input-group > .ivu-input:last-child,
/deep/.ivu-input-group-append {
  background: none;
  color: #999999;
}
/deep/.ivu-input-group .ivu-input {
  border-right: 0px !important;
}
.content /deep/.ivu-form .ivu-form-item-label {
  width: 133px;
}
.topIput {
  width: 186px;
  background: #ffffff;
  border-right: 0px !important;
}
.abbreviation {
  .top {
    display: flex;
    justify-content: flex-start;
    .topBox {
      display: flex;
      .topRight {
        width: 254px;
        margin-left: 36px;
      }
      .topLeft {
        width: 94px;
        height: 94px;

        text-align: center;
        font-size: 13px;
        font-weight: 400;
        color: #000000;
        .img {
          // width: 84px;
          height: 67px;
          background: #f7fbff;
          border-radius: 4px;
          margin-bottom: 9px;
          .imgs {
            width: 70px;
            height: 51px;
            display: inline-block;
            text-align: center;
            margin-top: 8px;
          }
        }
      }
    }
  }
  .content {
    /deep/.ivu-form-item-label {
      width: 120px;
    }
    .flex {
      display: flex;
      justify-content: flex-start;
      // width: 400px;

      .contentIput {
        width: 400px;
      }
      .conents {
        display: flex;
        .title {
          width: 30px;
          margin-top: 70px;
          margin-left: 6px;
        }
        .positionBox {
          display: flex;
          flex-wrap: wrap;
          width: 101px;
          height: 99px;
          border-right: 1px solid #dddddd;
          .box {
            width: 33px;
            height: 33px;
            // border-radius: 4px 0px 0px 0px;
            border: 1px solid #dddddd;
            cursor: pointer;
          }
          .on {
            background: rgba(24, 144, 255, 0.1);
          }
        }
      }
    }
  }
}
</style>
<style scoped>
.message /deep/ .ivu-table-header thead tr th {
  padding: 8px 16px;
}
.ivu-radio-wrapper {
  margin-right: 15px;
  font-size: 12px !important;
}
.message /deep/ .ivu-tabs-tab {
  border-radius: 0 !important;
}
.table-box {
  padding: 20px;
}
.is-table {
  display: flex;
  /* justify-content: space-around; */
  justify-content: center;
}
.btn {
  cursor: pointer;
  color: #2d8cf0;
  font-size: 10px;
}
.is-switch-close {
  background-color: #504444;
}
.is-switch {
  background-color: #eb5252;
}
.notice-list {
  background-color: #308cf5;
  margin: 0 15px;
}
.table {
  padding: 0 18px;
}
.confignv {
  margin: 10px 0px;
}
.configtit {
  display: inline-block;
  width: 60px;
  text-align: right;
}
.copy {
  padding: 3px 5px;
  border: 1px solid #cccccc;
  border-radius: 5px;
  color: #333;
  cursor: pointer;
  margin-left: 5px;
}
.copy:hover {
  border-color: #2d8cf0;
  color: #2d8cf0;
}
.picBox {
  display: inline-block;
  cursor: pointer;
}
.picBox .pictrue {
  width: 60px;
  height: 60px;
  border: 1px dotted rgba(0, 0, 0, 0.1);
  margin-right: 10px;
}

.picBox .pictrue img {
  width: 100%;
  height: 100%;
}
.picBox .upLoad {
  width: 58px;
  height: 58px;
  line-height: 58px;
  border: 1px dotted rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.02);
}
h3 {
  margin: 5px 0 15px 0;
}
.table-box p {
  margin-bottom: 10px;
}
.save-type {
  font-size: 13px;
}
.attach{
	
}
.file{
	margin-right: 15px;
}
.file:hover{
	text-decoration: underline;
}
</style>
